package test.java;

import java.io.*;

public class SeriCtrol implements Serializable {
    private static final long serialVersionUID = -4994939941552821559L;

    private String a;

    private String b;

    private transient String c;

    public SeriCtrol(String a, String b, String c) {
        this.a = "非瞬时默认实现:" + a;
        this.b = "非瞬时非默认实现:" + b;
        this.c = "瞬时实现:" + c;
    }

//    private void writeObject(ObjectOutputStream stream) throws IOException {
//        stream.defaultWriteObject();
//        stream.writeObject(b);
//        stream.writeObject(c);
//    }

//    private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
//        stream.defaultReadObject();
//        stream.readObject();
//        b = "null";
//        c = (String) stream.readObject();
//    }

    public String toString() {
        return a + " -> " + b + " -> " + c;
    }

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        SeriCtrol sCtrol = new SeriCtrol("test1", "test2", "test3");
        System.out.println("序列化之前");
        System.out.println(sCtrol);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(out);
        oos.writeObject(sCtrol);

        System.out.println("反序列化操作之后");
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(in);
        SeriCtrol src = (SeriCtrol) ois.readObject();
        System.out.println(src);
    }

}